var prefix = jsctx + "/member/equity";

var setting = (function () {
    function init() {
        validateRule();
    };
    var isajaxsend = true;

    function save() {
        var formData = new FormData($("#frmEquity")[0]);
        formData.append("tableLstStr",JSON.stringify(getValForString()));
        if (isajaxsend) {
            $.ajax({
                cache: true,
                type: "POST",
                url: prefix + "/saveSetting",
                data: formData,
                processData: false,
                contentType: false,
                // async: false,
                error: function (request) {
                    isajaxsend = true
                    console.log(request)
                    parent.layer.alert("Connection error");
                },
                success: function (data) {
                    if (data.status == 200) {
                        isajaxsend = false
                        parent.layer.msg("操作成功");
                        location.reload();
                    } else {
                        isajaxsend = true
                        parent.layer.alert(data.message)
                    }

                }
            });
        }
    }
    function getValForString() {
        var list = [];
        //获取到标签tr
        var trList = document.getElementById("chargeHandselId");//获取所有的table
        var rows = trList.rows;//获取所有行
        for(var i=1; i < rows.length; i++){
            var arr = {};
            var row = rows[i];//获取每一行
            arr["id"] = i;
            arr["rechargeAmount"] = row.cells[2].getElementsByTagName("INPUT")[0].value;
            arr["gainAmount"] = row.cells[3].getElementsByTagName("INPUT")[0].value;
            arr["consumeUseAmount"] = row.cells[4].getElementsByTagName("INPUT")[0].value;
            list.push(arr);
        }
        return list;
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#frmEquity").validate({
            rules: {

            },
            messages: {

            },
            submitHandler: function (form) {
                save();
            }
        })
    }
    return {
        init: init
    };
})();
